package myzzyl.controller;



import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.FloorDto;
import myzzyl.domain.pojo.Floor;
import myzzyl.domain.vo.FloorVo;
import myzzyl.response.BaseResponse;
import myzzyl.service.FloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/floor")
@Tag(name = "楼层相关")
@Slf4j
public class FloorController {

    @Autowired
    private FloorService floorService;

    /**
     * 获取所有楼层
     */
    @GetMapping("/getAll")
    public BaseResponse<List<Floor>> getAll() {
        log.info("获取所有楼层");
        List<Floor> floorList = floorService.getAll();
        return BaseResponse.success(floorList);
    }

    /**
     * 获取楼层详情
     */
    @GetMapping("/get/{id}")
    public BaseResponse<Floor> getInfo(@PathVariable Long id) {
        log.info("获取楼层详情:{}", id);
        return BaseResponse.success(floorService.getInfo(id));
    }


    /**
     * 新增楼层
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> add(@RequestBody FloorDto floorDto) {
        log.info("新增楼层:{}", floorDto);
        return BaseResponse.success(floorService.add(floorDto));
    }


    /**
     * 编辑楼层
     */
    @PutMapping("/update")
    public BaseResponse<Boolean> edit(@RequestBody FloorDto floorDto) {
        log.info("编辑楼层:{}", floorDto);
        return BaseResponse.success(floorService.edit(floorDto));
    }

    /**
     * 删除楼层
     */
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> remove(@PathVariable Long id) {
        log.info("删除楼层:{}", id);
        return BaseResponse.success(floorService.deleteFloorById(id));
    }

    /**
     * 获取所有楼层下的房间和床位
     */
    @GetMapping("/getAllWithRoomAndBed")
    public BaseResponse<List<FloorVo>> getAllWithRoomAndBed() {
        log.info("获取所有楼层下的房间和床位");
        return BaseResponse.success(floorService.getAllWithRoomAndBed());
    }
}
